<link href="/classico/public/assets/all-site/css/jquery-ui.min.css"
      rel="stylesheet" type="text/css"/>
<link href="/classico/public/back-end/css/feedback/index.css"
      rel="stylesheet" type="text/css"/>
<script type="text/javascript"
        src="/classico/public/assets/all-site/js/jquery-ui.min.js"></script>
<div class="system-messages">
    <ul>
        <?php
        $messages = $this->messages;
        foreach ($messages as $message) :
            ?>
            <li><?= $message ?></li>
        <?php
        endforeach
        ?>
    </ul>
</div>
<div class="admin-search-n-filter">
    <div class="admin-search">
        <label><input type="text" value="<?= $this->enteredKeyWords ?>"/></label>
        <input type="button" value=""/>
    </div>
    <div class="admin-hyperlink-btn">
        <a href="/classico/public/admin/feedback/index">Refresh</a>
    </div>
    <div class="admin-filter">
        <label>
            <select>
                <?php
                if (!isset($this->isProcess)) :
                    ?>
                    <option value="null">-- Is Process --</option>
                    <option value="1">True</option>
                    <option value="0">False</option>
                <?php
                endif;
                if ($this->isProcess === true) :
                    ?>
                    <option value="null">-- Is Process --</option>
                    <option value="1" selected="selected">True</option>
                    <option value="0">False</option>
                <?php
                endif;
                if ($this->isProcess === false) :
                    ?>
                    <option value="null">-- Is Process --</option>
                    <option value="1">True</option>
                    <option value="0" selected="selected">False</option>
                <?php
                endif;
                ?>
            </select>
        </label>
    </div>
</div>
<div>
    <div class="datagrid">
        <table>
            <tr>
                <th width="2%">ID</th>
                <th>Title</th>
                <th width="11%">Author</th>
                <th width="11%">CreatedDate</th>
                <th width="5%">UserID</th>
                <th width="5%" class="center">IsProcess</th>
            </tr>
            <?php
            $feedbacks = $this->feedbacks;
            foreach ($feedbacks as $index => $feedback) :
                ?>
                <tr class="<?= ($index % 2 == 0) ? 'alt' : '' ?>">
                    <td><?= $feedback['ID'] ?></td>
                    <td id="feedback-title-<?= $feedback['ID'] ?>">
                        <a><?= $feedback['Title'] ?></a>

                        <div id="feedback-content-<?= $feedback['ID'] ?>"
                             class="feedback-content" title="Content">
                            <?= $feedback['Content'] ?>
                        </div>
                    </td>
                    <td><?= $feedback['Author'] ?></td>
                    <td><?= $feedback['CreatedDate'] ?></td>
                    <td><?= $feedback['UserID'] ?></td>
                    <td class="center">
                        <?php
                        if (!$feedback['IsProcess']) :
                            ?>
                            <div class="enabled-block-icon tool-icon"></div>
                            <form action="/classico/public/admin/feedback/confirm"
                                  method="post">
                                <input type="hidden" name="isPost" value=""/>
                                <input type="hidden" name="feedbackID"
                                       value="<?= $feedback['ID'] ?>"/>
                            </form>
                        <?php
                        endif;
                        if ($feedback['IsProcess']) :
                            ?>
                            <div class="enabled-confirm-icon tool-icon"></div>
                            <form action="/classico/public/admin/feedback/unconfirm"
                                  method="post">
                                <input type="hidden" name="isPost" value=""/>
                                <input type="hidden" name="feedbackID"
                                       value="<?= $feedback['ID'] ?>"/>
                            </form>
                        <?php
                        endif
                        ?>
                    </td>
                </tr>
            <?php
            endforeach
            ?>
        </table>
    </div>
</div>
<?= $this->paginationControl($this->paginator, 'Sliding', 'my_pagination_control.phtml') ?>
<script type="text/javascript">
    $('#tool-btn-add, #tool-btn-delete, #tool-btn-update')
        .removeClass('enabled-tool-btn');
    $('#tool-btn-confirm, #tool-btn-unblock, #tool-btn-block')
        .removeClass('enabled-tool-btn');

    $('#tool-btn-add > div')
        .removeClass('enabled-add-icon')
        .addClass('disabled-add-icon');
    $('#tool-btn-delete > div')
        .removeClass('enabled-delete-icon')
        .addClass('disabled-delete-icon');
    $('#tool-btn-update > div')
        .removeClass('enabled-update-icon')
        .addClass('disabled-update-icon');
    $('#tool-btn-confirm > div')
        .removeClass('enabled-confirm-icon')
        .addClass('disabled-confirm-icon');
    $('#tool-btn-unblock > div')
        .removeClass('enabled-unblock-icon')
        .addClass('disabled-unblock-icon');
    $('#tool-btn-block > div')
        .removeClass('enabled-block-icon')
        .addClass('disabled-block-icon');
</script>
<script type="text/javascript">
    function forwardHyperlink() {
        var currentURL = location.href;

        var forwardURL = currentURL.replace(/\/feedback\/[\w\W]*/, '');
        forwardURL = forwardURL.replace(/\/index\/[\w\W]*/, '');
        forwardURL = forwardURL.replace(/\/keyWords\/[\w\W]*/, '');
        forwardURL = forwardURL.replace(/\/isProcess\/[\w\W]*/, '');
        forwardURL = forwardURL.replace(/\/page\/[\w\W]*/, '');

        forwardURL += '/feedback/index';

        var keyWords = $('.admin-search input[type = "text"]').val();
        if (keyWords) {
            forwardURL += '/keyWords/' + keyWords;
        }

        var isProcessValue = $('.admin-filter select').val();
        if (isProcessValue != 'null') {
            forwardURL += '/isProcess/' + isProcessValue;
        }

        window.location.href = forwardURL;
    }

    $('.admin-search input[type = "text"]').keydown(function (event) {
        if (event.which == 13) {
            forwardHyperlink();
        }
    });

    $('.admin-search input[type = "button"]').click(function () {
        forwardHyperlink();
    });

    $('.admin-filter select').change(function () {
        forwardHyperlink();
    });
</script>
<script type="text/javascript">
    <?php
    foreach ($feedbacks as $feedback) :
    ?>
    var id = '<?= $feedback['ID'] ?>';

    $('#feedback-content-' + id).dialog({
        autoOpen: false,
        show: {
            effect: 'fade',
            duration: 300
        },
        hide: {
            effect: 'fade',
            duration: 300
        }
    });

    $('#feedback-title-' + id + ' a').click(function () {
        $('#feedback-content-' + <?= $feedback['ID'] ?>).dialog('open');
    });
    <?php
    endforeach
    ?>

    $('.datagrid .tool-icon').click(function () {
        $(this).parent(null).find('form').submit();
    });
</script>
